package org.jeecg.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.domain.CommonUser;
import org.jeecg.domain.util.ResponseResult;
import org.jeecg.domain.vo.CommonUserVo;
import org.jeecg.service.CommonUserService;
import org.jeecg.mapper.CommonUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author w
* @description 针对表【common_user】的数据库操作Service实现
* @createDate 2024-12-24 20:08:46
*/
@Service
public class CommonUserServiceImpl extends ServiceImpl<CommonUserMapper, CommonUser>
    implements CommonUserService{
    @Autowired
    private CommonUserMapper commonUserMapper;

    @Override
    public ResponseResult listcommon(CommonUserVo commonUserVo) {
        IPage<CommonUser> page = new Page<>(commonUserVo.getPageNum(), commonUserVo.getPageSize());
        LambdaQueryWrapper<CommonUser> queryWrapper = new LambdaQueryWrapper<>();
        if (commonUserVo.getNickname()!= null) {
            queryWrapper.like(CommonUser::getNickname, commonUserVo.getNickname());
        }
        if (commonUserVo.getPhone()!= null) {
            queryWrapper.like(CommonUser::getPhone, commonUserVo.getPhone());
        }
        this.page(page, queryWrapper);
        return ResponseResult.okResult(page);
    }

    @Override
    public ResponseResult updatestauts(Long id) {
        // 检查 id 是否为 null
        if (id == null) {
            return ResponseResult.errorResult(400, "ID不能为空");
        }

        // 根据传入的id从数据库中查询出对应的ServeType对象
        CommonUser serveType = commonUserMapper.selectById(id);
        if (serveType == null) {
            return ResponseResult.errorResult(400, "未找到对应ID的服务类型记录");
        }

        // 假设这里根据业务需求来更新activeStatus字段，你可以根据实际情况调整更新逻辑
        serveType.setStatus(serveType.getStatus() == 0? 1 : 0);

        // 执行更新操作
        int updateRows = commonUserMapper.updateById(serveType);
        if (updateRows == 1) {
            return ResponseResult.okResult("更新成功");
        } else {
            return ResponseResult.errorResult(500, "更新失败，数据库操作出现问题");
        }
    }
}




